package com.gitee.zycra.future.job.common.vo;

import com.gitee.zycra.future.job.common.model.JobSchedule;
import com.gitee.zycra.jdbc.annotation.Table;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;

/**
 * @author zycra
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
@Table
public class JobScheduleVO {

    /**
     * 主键
     */
    private Long id;

    /**
     * 调度名称
     */
    private String scheduleName;

    /**
     * 执行参数
     */
    private String scheduleParam;

    /**
     * 月
     */
    private Integer cronMonth;

    /**
     * 日
     */
    private Integer cronDay;

    /**
     * 时
     */
    private Integer cronHour;

    /**
     * 分
     */
    private Integer cronMinute;

    /**
     * 秒
     */
    private Integer cronSecond;

    /**
     * 是否开启(0:否,1:是)
     */
    private Boolean scheduleEnable;

    /**
     * 上次调度时间
     */
    private LocalDateTime lastScheduleTime;

    /**
     * 下次调度时间
     */
    private LocalDateTime nextScheduleTime;

    /**
     * 正常下次调度时间
     */
    private LocalDateTime normalNextTime;

    /**
     * 操作人姓名
     */
    private String operatorName;

    /**
     * 更新时间
     */
    private LocalDateTime updateTime;

    /**
     * 执行周期
     *
     * @see com.gitee.zycra.future.job.common.enums.JobCycleEnum
     */
    private Integer jobCycle;

    public static JobScheduleVO buildJobScheduleVO(JobSchedule jobSchedule, Integer jobCycle) {
        if (jobSchedule == null) {
            return null;
        }
        return new JobScheduleVO().setId(jobSchedule.getId())
                .setScheduleName(jobSchedule.getScheduleName())
                .setScheduleParam(jobSchedule.getScheduleParam())
                .setCronMonth(jobSchedule.getCronMonth())
                .setCronDay(jobSchedule.getCronDay())
                .setCronHour(jobSchedule.getCronHour())
                .setCronMinute(jobSchedule.getCronMinute())
                .setCronSecond(jobSchedule.getCronSecond())
                .setScheduleEnable(jobSchedule.getScheduleEnable())
                .setLastScheduleTime(jobSchedule.getLastScheduleTime())
                .setNextScheduleTime(jobSchedule.getNextScheduleTime())
                .setNormalNextTime(jobSchedule.getNormalNextTime())
                .setOperatorName(jobSchedule.getOperatorName())
                .setUpdateTime(jobSchedule.getUpdateTime())
                .setJobCycle(jobCycle);
    }
}
